package xin.petstore.framework.orm.mybatis.paginator;

import xin.petstore.framework.orm.mybatis.paginator.domain.PageList;
import xin.petstore.framework.orm.mybatis.paginator.domain.Paginator;
import xin.petstore.framework.sevice.api.PageResultDTO;
import xin.petstore.framework.utils.BeanMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class PaginatorUtil {
    public static <T> PageResultDTO<T> mapList(List<?> sourceList, Class<T> destinationClass) {
        List destinationList = new ArrayList();
        PageResultDTO result = new PageResultDTO();
        if ((sourceList instanceof PageList)) {
            PageList list = (PageList) sourceList;
            for (Iterator localIterator = list.iterator(); localIterator.hasNext(); ) {
                Object sourceObject = localIterator.next();
                Object destinationObject = BeanMapper.map(sourceObject,
                        destinationClass);
                destinationList.add(destinationObject);
            }
            result.setTotalCount(list.getPaginator().getTotalCount());
            result.setTotalPages(list.getPaginator().getTotalPages());
            result.setPage(list.getPaginator().getPage());
            result.setLimit(list.getPaginator().getLimit());
            result.setItems(destinationList);

            result.setStartRow(list.getPaginator().getStartRow());
            result.setEndRow(list.getPaginator().getEndRow());

            result.setOffset(list.getPaginator().getOffset());
            result.setSlider(list.getPaginator().getSlider());
            result.setPrePage(list.getPaginator().getPrePage());
            result.setNextPage(list.getPaginator().getNextPage());

            result.setFirstPage(list.getPaginator().isFirstPage());
            result.setHasNextPage(list.getPaginator().isHasNextPage());
            result.setHasPrePage(list.getPaginator().isHasPrePage());
            result.setLastPage(list.getPaginator().isLastPage());
            return result;
        }
        return null;
    }

    public static <T> Map<String, Object> toList(List<?> sourceList, Class<T> destinationClass) {
        Map map = new HashMap();
        if ((sourceList instanceof PageList)) {
            PageList values = (PageList) sourceList;

            Paginator paginator = values.getPaginator();
            map.put("totalCount", Integer.valueOf(paginator.getTotalCount()));
            map.put("totalPages", Integer.valueOf(paginator.getTotalPages()));
            map.put("page", Integer.valueOf(paginator.getPage()));
            map.put("limit", Integer.valueOf(paginator.getLimit()));
            List destinationList = new ArrayList();
            for (Iterator localIterator = values.iterator(); localIterator.hasNext(); ) {
                Object sourceObject = localIterator.next();
                Object destinationObject = BeanMapper.map(sourceObject,
                        destinationClass);
                destinationList.add(destinationObject);
            }
            map.put("items", destinationList);

            map.put("startRow", Integer.valueOf(paginator.getStartRow()));
            map.put("endRow", Integer.valueOf(paginator.getEndRow()));

            map.put("offset", Integer.valueOf(paginator.getOffset()));

            map.put("slider", paginator.getSlider());

            map.put("prePage", Integer.valueOf(paginator.getPrePage()));
            map.put("nextPage", Integer.valueOf(paginator.getNextPage()));

            map.put("firstPage", Boolean.valueOf(paginator.isFirstPage()));
            map.put("hasNextPage", Boolean.valueOf(paginator.isHasNextPage()));
            map.put("hasPrePage", Boolean.valueOf(paginator.isHasPrePage()));
            map.put("lastPage", Boolean.valueOf(paginator.isLastPage()));
        }
        return map;
    }
}

/* Location:           C:\java代码反编译器\core-1.1.4.jar
 * Qualified Name:     com.eloancn.framework.orm.mybatis.paginator.PaginatorUtil
 * JD-Core Version:    0.6.0
 */